package com.project.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.project.bean.ProductBean;
import com.project.mapper.IProductMapper;
import com.project.service.IProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDate;

@Service
@Transactional
public class ProductServiceImpl implements IProductService {
    @Autowired
    private IProductMapper mapper;

    @Override
    public PageInfo<ProductBean> findByItem(int pageNO, String name, LocalDate startDate, LocalDate endDate) {
        PageHelper.startPage(pageNO,PAGESIZE);
        PageInfo<ProductBean> info = PageInfo.of(
                mapper.findByItem(name,startDate,endDate));

        return info;
    }

    @Override
    public void add(ProductBean product) {
        mapper.add(product);
    }

    @Override
    public void del(int id) {
        mapper.del(id);
    }

    @Override
    public void update(int id, int price) {
        mapper.update(id,price);
    }

    @Override
    public ProductBean findById(int id) {
        return mapper.findById(id);
    }
}
